<template>
	<view class="body_css">
		<!-- 顶部高度 -->
		<appNav bgColor="transparent" color="#fff" :show-back-icon="false" />

		<!-- 中间内容 -->
		<view class="logo_css">
			<image src="https://seven-3121.obs.cn-north-4.myhuaweicloud.com/2025%2F7%2F6%2F%E7%BB%84+117732%401x.png" />
		</view>

		<!-- 登录 -->
		<view class="p_css">
			<view class="p_text">
				<view>
					欢迎登录第七届文博会
				</view>
				<view>
					外联商户核销后台
				</view>
			</view>
			<view class="form_view">
				<view class="form_item">
					<view class="form_label">
						账号
					</view>
					<view class="form_cont">
						<input type="text" v-model="form.username" placeholder="请输入" clearable />
					</view>
				</view>
				<view class="form_item">
					<view class="form_label">
						密码
					</view>
					<view class="form_cont">
						<input v-model="form.password" placeholder="请输入密码" :password="showPassword" />
						<view class="pass_icon" @click="changePassword">
							<image v-if="showPassword"
								src="https://seven-3121.obs.cn-north-4.myhuaweicloud.com/2025%2F7%2F15%2Fshow_o.png"
								mode="" />
							<image v-else
								src="https://seven-3121.obs.cn-north-4.myhuaweicloud.com/2025%2F7%2F15%2Fshow.png"
								mode="" />
						</view>
					</view>
				</view>

				<!-- 隐私政策 -->
				<view class="yes_css">
					<uv-checkbox-group v-model="checkout">
						<uv-checkbox shape="square" label="" :name="1" active-color="#438DFF">
							<view class="agree">
								<view>
									我已阅读并同意
								</view>
								<view class="gray_css" @click.stop="handleAgree('/pages/user/user_agree')">
									《用户服务协议》
								</view>
								<view>
									和
								</view>
								<view class="gray_css" @click.stop="handleAgree('/pages/user/privacy_agree')">
									《隐私政策》
								</view>
							</view>
						</uv-checkbox>
					</uv-checkbox-group>
				</view>

				<view class="btn_css" @click="loginSet">
					开始登录
				</view>
			</view>
		</view>

	</view>

</template>

<script>
	import {
		login,
	} from '@/stores/app-store'

	export default {
		components: {},
		data() {
			return {
				checkout: [],
				form: {
					username: "",
					password: "",
				},

				showPassword: true,
			}
		},


		methods: {
			// 查看密码
			changePassword() {
				this.showPassword = !this.showPassword;
			},

			handleLogin() {
				if (this.checkout.length !== 1) {
					uni.showToast({
						title: '请先阅读并勾选用户协议',
						icon: 'none',
					})
					return false
				}
				return true
			},


			loginSet() {
				if (!this.form.username) {
					uni.showToast({
						title: '请输入账号',
						icon: 'none',
					})
					return
				}

				if (!this.form.password) {
					uni.showToast({
						title: '请输入密码',
						icon: 'none',
					})
					return
				}

				if (!this.handleLogin()) {
					return
				}

				uni.showLoading({
					title: '登录中...',
					mask: true
				})
				login(
					this.form
				).catch(() => {
					uni.hideLoading()
				})


				setTimeout(() => {
					var data = uni.getStorageSync('loginRes')
					if (data) {
						var loginRes = JSON.parse(data)
						uni.hideLoading()

						if (loginRes.code === 200) {
							uni.showToast({
								title: '登录成功',
								icon: 'none',
							})

						} else {
							uni.showToast({
								title: loginRes.msg,
								icon: 'none'
							})
						}
					}
				}, 500)
			},

			handleAgree(path) {
				uni.navigateTo({
					url: path
				})
			},
		}
	}
</script>

<style>
	.ys_css .uv-checkbox-group {
		justify-content: center;
	}
</style>
<style scoped>
	@import url("index.css");
</style>